home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / VideoToolbox 96.06.15 / VideoToolboxSources / AfterDark.c next >
Text File  |  1996-05-29  |  3KB  |  115 lines

  1. /* AfterDark.c
  2.  
  3. error=AfterDarkDisable();
  4. error=AfterDarkEnable();
  5.  
  6. Disable and later re-enable the popular screen saver, AfterDark. An error code is
  7. returned if the relevant Gestalt selectors are not installed, i.e. no
  8. AfterDark-compatible screen saver is present.
  9.  
  10. Written by David Brainard, based on documentation supplied by Berkeley Systems
  11. Mac Tech Support, brklysystm@aol.com. Ask them for the AfterDarkGestalt.h file.
  12.  
  13. The interface to the screen saver is generic. Any screen saver that installs the
  14. same Gestalt selectors would be controlled by these two routines, but we haven't
  15. tested that.
  16.  
  17. SEE ALSO:
  18. IsFileSharingOn.c
  19.  
  20. HISTORY:
  21. 6/15/95    dhb        Wrote it.
  22. 6/16/95    dhb        Don't call procedure on PPC, as it causes a crash.    
  23. 6/20/95    dhb        Make it work on PPC, use symbol GENERATING68K.
  24. 6/21/95    dhb        Conditional compiles so that it will still work on 68K.
  25. 6/23/95 dgp        Removed the stuff that was MATLAB-specific. Renamed
  26.                             variables to make the code more self documenting.
  27. 6/23/95    dhb        Added necessary stuff from AfterDarkGestalt.h.
  28.                             Include VideoToolbox.h.
  29.                             Move prototypes to VideoToolbox.h.
  30. 5/288/96 dgp Changed <VideoToolbox.h> to  "VideoToolbox.h"
  31. */
  32.  
  33. #include "VideoToolbox.h"
  34.  
  35. // Gestalt called with 'SAVR' selector returns longword bitmask.
  36. #define gestaltScreenSaverAttr 'SAVR'
  37. enum {
  38.     gestaltSaverTurnedOn = 0,                        /* saver enabled/disabled. */
  39.     gestaltSaverAsleep,                                    /* saver currently asleep. */
  40.     gestaltSaverDemoMode,                                /* saver sleeping in demo mode. */
  41.     gestaltSaverPasswordMode,                        /* saver sleeping in password-protected mode. */
  42.     gestaltAppDrawingDisabled                        /* Quickdraw drawing disallowed between module animation frames. */
  43. };
  44.  
  45. // Gestalt called with 'SAVC' selector returns a pointer
  46. // to a procedure.  Pass the appropriate command
  47. #define gestaltScreenSaverControl 'SAVC'
  48. enum SaverCommand {
  49.     gestaltSaverWakeUp,
  50.     gestaltSaverSleep,
  51.     
  52.     /* defined in AD 2.0x and later */
  53.     gestaltSaverOn,
  54.     gestaltSaverOff,
  55.     
  56.     /* defined for AD 3.0 and later */
  57.     gestaltSysIQOn,
  58.     gestaltSysIQOff,
  59.     
  60.     gestaltForceShort = 257
  61. };
  62. typedef short SaverCommand;
  63. typedef pascal OSErr (*SaverControlProcPtr) (SaverCommand command);
  64.  
  65. static OSErr AfterDarkCommand(SaverCommand command);
  66.  
  67. #if !GENERATING68K
  68.     enum {
  69.         uppSaverProcInfo=kPascalStackBased
  70.              | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  71.              | STACK_ROUTINE_PARAMETER(1,SIZE_CODE(sizeof(SaverCommand)))
  72.     };
  73. #endif
  74.  
  75.  
  76. OSErr AfterDarkEnable(void)
  77. {
  78.     return AfterDarkCommand(gestaltSaverOn);    
  79. }
  80.  
  81.  
  82. OSErr AfterDarkDisable(void)
  83. {
  84.     return AfterDarkCommand(gestaltSaverOff);    
  85. }
  86.  
  87. static OSErr AfterDarkCommand(SaverCommand command)
  88. {
  89.     OSErr error;
  90.     long response;
  91.     SaverControlProcPtr saverProcPtr;
  92.     #if !GENERATING68K
  93.         UniversalProcPtr saverUPP=NULL;
  94.     #endif
  95.  
  96.     // Make sure the screen saver is installed, return if not.
  97.     error=Gestalt(gestaltScreenSaverAttr,&response);
  98.     if(error)return error;    
  99.     
  100.     // Get a pointer to the screen saver's control procedure
  101.     error=Gestalt(gestaltScreenSaverControl,(long *)&saverProcPtr);
  102.     if(error)return error;    
  103.     
  104.     // Ask the control procedure to perform the command
  105.     #if GENERATING68K
  106.         error=(*saverProcPtr)(command);
  107.     #else
  108.         saverUPP=NewRoutineDescriptor((ProcPtr)saverProcPtr,uppSaverProcInfo,kM68kISA);
  109.         if(saverUPP==NULL)return 1;    // Memory allocation failed.
  110.         error=(OSErr)CallUniversalProc(saverUPP,uppSaverProcInfo,command);
  111.         DisposeRoutineDescriptor(saverUPP);
  112.     #endif
  113.     return error;
  114. }
  115.